﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.IO;

namespace AdaptiveAgents.Running_Tools
{
    /// <summary>
    /// This Class create agent data list
    /// </summary>
    class AgentDataListCreaator
    {
        /// <summary>
        /// This function create random agent data list
        /// </summary>
        /// <param name="list">List of agents type</param>
        /// <returns>List of agents data</returns>
        public static List<AgentInput> getRandomList(List<string> list)
        {
            Random r = new Random();
            List<AgentInput> returnList = new List<AgentInput>();
            Hashtable hash = new Hashtable();
            double eps = 0;
            double comp = 0;
            int counter = 0;
            AgentInput agent = null;

            while (counter < list.Count)
            {
                // choose new epsilon
                eps = r.NextDouble();
                while (hash.ContainsKey(eps)) { eps = r.NextDouble(); }
                hash.Add(eps,eps);
                // choose new competence
                comp = r.NextDouble();
                agent = new AgentInput(list[counter], eps, comp);
                returnList.Add(agent);
                ++counter;
            }

            return returnList;
        }


        /// <summary>
        /// This function create agent data list from file
        /// </summary>
        /// <param name="list">List of agents type</param>
        /// <param name="filePath">File path for agents data</param>
        /// <returns>List of agents data</returns>
        public static List<AgentInput> getListFromFile(List<string> list, String filePath)
        {
            List<AgentInput> returnList = new List<AgentInput>();
            StreamReader reader = new StreamReader(filePath);
            String line = null;
            string[] parseLine = null;
            int counter = 0;
            double comp, eps;

            reader.ReadLine();

            while(counter < list.Count){
                line = reader.ReadLine();
                parseLine = line.Split(',');

                // get epsilon
                eps = Convert.ToDouble(parseLine[0]);

                // get competence
                comp = Convert.ToDouble(parseLine[1]);

                returnList.Add(new AgentInput(list[counter], eps, comp));
                counter++;
            }
            reader.Close();
            return returnList;
        }
    }
}
